<?php

namespace App\Http\Controllers;

use App\Measures;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class MeasureController extends Controller
{
    public function store(Request $request)
    {
        Log::info(array_keys($request->all())[0]);
        if( !empty(array_keys($request->all())))
        {
            $resString = array_keys($request->all())[0];
            if(preg_match('/^[0-9]+,[0-9]+$/',$resString))
            {
                $humidity = explode(',',$resString)[1];
                $temperature = explode(',',$resString)[0];
                $measureObj = new Measures();
                $measureObj->humidity = intval($humidity);
                $measureObj->temperature = intval($temperature) ;
                $measureObj->save();
                return 'ok' . $humidity . ',' .$temperature;
            }
        }

        return ['code'=>0,'msg'=>'成功'];
    }
}
